//package com.example.interceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.aspectj.lang.annotation.AfterReturning;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//
//import com.example.producer.KafkaProducer;
//import com.example.vo.DemoMessage;
//
///**
// * AOP拦截请求并转发到Kafka
// * 
// * @author Tanlian
// * @create 2018-11-18 15:24
// **/
//@Component
//public class RequestInterceptor extends HandlerInterceptorAdapter {
//
//	@Autowired
//	private KafkaProducer kafkaProducer;
//
//	private Logger logger = LoggerFactory.getLogger(RequestInterceptor.class);
//
//	@Override
//	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
//			throws Exception {
//		boolean sign = true;
//		logger.info("HTTP_METHOD : " + request.getMethod());
//		logger.info("IP : " + request.getRemoteAddr());
//		logger.info(String.valueOf(System.currentTimeMillis()));
//		DemoMessage message = new DemoMessage();
//		message.setRequest(request);
//		message.setResponse(response);
////		logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
////				+ joinPoint.getSignature().getName());
////		logger.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
//		kafkaProducer.send(message);
//		// kafkaProducer.send(request);
//
//		return sign;
//
//	}
//	/**
//	 * 定义切入点，切入点为com.example.controller下的所有函数
//	 */
////	@Pointcut("execution(com.example.controller.*.*(..))")
////	public void webLog() {
////
////	}
//
//	/**
//	 * 前置通知：在连接点之前执行的通知
//	 * 
//	 * @param joinPoint
//	 * @throws Throwable
//	 */
////	@Before("webLog()")
////	public void doBefore(JoinPoint joinPoint) throws Throwable {
////		// 接收到请求，记录请求内容
////		ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
////		HttpServletRequest request = attributes.getRequest();
////
////		// 记录下请求内容
////		logger.info("HTTP_METHOD : " + request.getMethod());
////		logger.info("IP : " + request.getRemoteAddr());
////		logger.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "."
////				+ joinPoint.getSignature().getName());
////		logger.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
////		kafkaProducer.send(request);
////	}
//
//	@AfterReturning(returning = "ret", pointcut = "webLog()")
//	public void doAfterReturning(Object ret) throws Throwable {
//		// 处理完请求，返回内容
////		kafkaProducer.send();
//		logger.info("RESPONSE : " + ret);
//	}
//}
